package com.leihao.product.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.leihao.common.core.exception.ServiceException;
import com.leihao.common.core.utils.StringUtils;
import com.leihao.product.domian.listRequest.ListRequest;
import com.leihao.product.domian.ProductAttr;
import com.leihao.product.mapper.ProductAttrMapper;
import com.leihao.product.service.ProductAttrService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ProductAttrServiceImpl implements ProductAttrService {
    @Autowired
    private ProductAttrMapper productAttrMapper;

    @Override
    public PageInfo<ProductAttr> findList(ListRequest listRequest) {
        if (StringUtils.isNull(listRequest)) {
            throw new ServiceException("参数异常!不能为空");
        }
        PageHelper.startPage(listRequest.getPageNum(), listRequest.getPageSize());
        List<ProductAttr> list = productAttrMapper.findList();
        PageInfo<ProductAttr> productAttrPageInfo = new PageInfo(list);
        return productAttrPageInfo;
    }

    @Override
    public ProductAttr findById(Integer productAttrId) {
        if (productAttrId == null) {
            throw new ServiceException("参数异常!不能为空");
        }
        ProductAttr productAttr = productAttrMapper.findById(productAttrId);
        return productAttr;
    }

    @Override
    public void delete(Integer productAttrId) {
        if (productAttrId == null) {
            throw new ServiceException("参数异常!不能为空");
        }
        productAttrMapper.delete(productAttrId);
    }

    @Override
    public void update(ProductAttr productAttr) {
        if (StringUtils.isNull(productAttr)) {
            throw new ServiceException("参数异常!不能为空");
        }
        if (productAttr.getProductAttrId() == null) {
            throw new ServiceException("参数异常!修改编号不能为空");
        }
        productAttrMapper.update(productAttr);
    }

    @Override
    public void add(ProductAttr productAttr) {
        if (StringUtils.isNull(productAttr)){
            throw new ServiceException("参数异常!不能为空");
        }
        productAttrMapper.add(productAttr);
    }



    @Override
    public List<ProductAttr> findAll() {
        return productAttrMapper.findAll();
    }
}
